package com.czk.model.observe;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/5/12 20:47
 */
public class WheatherData implements Subject{
    private float temperature;
    private float pressure;
    private float humidity;
    private CurrentCondition currentCondition;
    private List<Observer> observers=new ArrayList<>();


    public float getTemperature() {
        return temperature;
    }

    public float getPressure() {
        return pressure;
    }

    public float getHumidity() {
        return humidity;
    }

    /**
     * 温度变化
     * @param temperature
     * @param pressure
     * @param humidity
     */
    public void setData(float temperature,float pressure,float humidity){
        this.temperature=temperature;
        this.pressure=pressure;
        this.humidity=humidity;
        // 提醒观察者改变
        dataChange();
    }
    // 改变
    public void dataChange(){
        // 通知所有
        notifyObservers();
    }
    // 注册观察者
    @Override
    public void Register(Observer observer) {
        observers.add(observer);
    }
    // 移除观察者
    @Override
    public void remove(Observer observer) {
        observers.remove(observer);
    }
    // 通知所有观察者
    @Override
    public void notifyObservers() {
        for (int i = 0; i <observers.size() ; i++) {
            // 通知所有观察者
            observers.get(i).update(temperature,pressure,humidity);
        }
    }
}
